package com.example.lklibrary.bi;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;

public class ActivityLifecycleListener implements Application.ActivityLifecycleCallbacks {

    /**
     * 应用存活时长
     */
    private long lauch;
    /**
     * 页面停留时长
     */
    private long pageDurash;

    @Override
    public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
    }

    @Override
    public void onActivityStarted(Activity activity) {
        lauch = System.currentTimeMillis();
        LKCollector.appLaunch(activity);
    }

    @Override
    public void onActivityResumed(Activity activity) {
       pageDurash = System.currentTimeMillis();
    }

    @Override
    public void onActivityPaused(Activity activity) {
        LKCollector.pageDuration(activity, String.valueOf(System.currentTimeMillis() - pageDurash), activity.getComponentName().getClassName());
    }

    @Override
    public void onActivityStopped(Activity activity) {
        LKCollector.appEnd(activity, String.valueOf(System.currentTimeMillis() - lauch));
    }

    @Override
    public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
    }

    @Override
    public void onActivityDestroyed(Activity activity) {

    }
}
